<?php
namespace Common\Controller;
use Think\Controller;
use Think\Auth;
class AuthController extends Controller
{
    protected function _initialize()
    {



        $sess_auth = session('tc');

        if (!$sess_auth) {
            $this->redirect('admin/login/index');
        }
        //更新通知消息
        if(isset($_GET['s_id']) && !empty($_GET['s_id'])){
            $s_id=$_GET['s_id'];
            M('Inform')->where("id=%d",$s_id)->save(['is_read'=>1]);
            return true;
        }
        if ($sess_auth['uid'] == 1) {
            $m_list=$this->menus(1);

            $this->assign('m_list',$m_list);
            return true;
        }
        $auth = new Auth();
        if (!$auth->check(CONTROLLER_NAME . '/' . ACTION_NAME, $sess_auth['uid'])) {

            $this->error('没有权限访问');
        }else{
            $group_id=$_SESSION['tc']['group_id'];

            $m_list=$this->menus($group_id);
            $this->assign('m_list',$m_list);
        }
    }
    //获取系统菜单
    protected function menus($group_id)
    {

        if($group_id==1){
            $map='';
        }else{
            $rules=M('AuthGroup')->where("id=%d",$group_id)->getField('rules');
            $map['id']=['in',$rules];
            $map['status']=1;
        }
        $menuList=M('AuthRule')->field("id,pid,title,name")->where($map)->order("sort ASC")->select();
        return manyL($menuList);
    }
}
